﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TestPlatform.Core;
using System.Data.SqlClient;

namespace TestPlatform.Performer.Mssql
{
    public class MssqlInsertPerformer : BaseInsertPerformer
    {
        public override string UnderlyinEngine { get { return "MSSQL"; } }

        public MssqlInsertPerformer()
            : base(new MssqlHelper())
        {

        }

        protected override void InsertEntity()
        {
            using (var c = MssqlHelper.CreateConnection())
            {
                Guid userId = Guid.NewGuid();

                SqlCommand cmd = c.CreateCommand();
                cmd.CommandText = string.Format("INSERT INTO [Users](Id, Login, Name) VALUES('{0}', '{1}', '{2}')", userId, userId, userId);
                cmd.ExecuteNonQuery();

                for (int i = 0; i < TestConfig.InsertSubEntitiesCount; i++)
                {
                    Guid postId = Guid.NewGuid();

                    cmd = c.CreateCommand();
                    cmd.CommandText = string.Format("INSERT INTO [Posts](Id, User_Id, Text) VALUES('{0}', '{1}', '{2}')", postId, userId, postId);
                    cmd.ExecuteNonQuery();
                }
            }
        }
    }
}
